package com.link.gateway.base.visitfrequency.controller;

import com.link.gateway.base.visitfrequency.service.VisitFrequencyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 接口访问统计controller，主要用于接收business服务发来的请求
 *
 * @author LiYang
 * @date 20190826
 */
@Controller
@RequestMapping("/link/frequencyControl")
public class VisitFrequencyController {

    @Resource
    private VisitFrequencyService visitFrequencyService;

    /**
     * 将缓存中的配置加载到本服务的内存中
     *
     * @author LiYang
     * @date 20190826
     */
    @RequestMapping(value = "/flushCache")
    @ResponseBody
    public Map<String, Object> flushCache() {
        Map<String, Object> result = new HashMap<String, Object>(2);
        boolean flag = visitFrequencyService.loadConfig();
        if (flag) {
            result.put("success", true);
        } else {
            result.put("success", false);
            result.put("result", "加载redis配置时出现异常");
        }
        return result;
    }
}
